package cn.com.suiyi.shixingshengxian.home.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.com.suiyi.shixingshengxian.R;
import cn.com.suiyi.shixingshengxian.home.bean.Vegetable;

/**
 * Created by hansen on 2016/7/19.
 */
public class HomeTestAdapter extends RecyclerView.Adapter<HomeTestAdapter.viewHold> {

    private Context context;
    private List<Vegetable.DataBean> list;

   public   interface VegetableClick{
        void setVegetableClick(View v,int position);
    }
   private VegetableClick vegetableClick;

    public void setVegetableClick(VegetableClick vegetableClick) {
        this.vegetableClick = vegetableClick;
    }

    public HomeTestAdapter(Context context, List<Vegetable.DataBean> list) {
        this.context = context;
        this.list = list;

    public HomeTestAdapter (Context context, List<Vegetable.DataBean> list){
        this.context=context;
        this.list=list;

    }


    @Override
    public viewHold onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_homeitem,null);
        viewHold hold=new viewHold(view);

        return hold;
    }

    @Override
    public void onBindViewHolder(viewHold holder, int position) {
//        holder.vegetable_title.setText(list.get(position).getTitle());
//        holder.vegetable_Description.setText(list.get(position).getDescription());
//
        holder.vegetable_Description.setText("1112");
        holder.vegetable_Description.setText("23");
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class viewHold extends RecyclerView.ViewHolder {
        TextView vegetable_title,vegetable_Description;
        RecyclerView recyclerView;
        public viewHold(View itemView) {
            super(itemView);
            vegetable_Description= (TextView) itemView.findViewById(R.id.vegetable_Description);
            vegetable_title= (TextView) itemView.findViewById(R.id.vegetable_title);
            recyclerView= (RecyclerView) itemView.findViewById(R.id.vegetable_recyclerview);


            FullGridLayoutManager manager=new FullGridLayoutManager(context,3);
            manager.setOrientation(LinearLayoutManager.VERTICAL);
            recyclerView.setLayoutManager(manager);
            vegeList=new ArrayList<>();
            adapter=new VegetableAdapter(R.layout.fragemtn_vegetableitem,vegeList,context);
            recyclerView.setAdapter(adapter);
//            Log.i("tag", "viewHold: 2222222");
//            adapter.setOnRecyclerViewItemChildClickListener(new BaseQuickAdapter.OnRecyclerViewItemChildClickListener() {
//                @Override
//                public void onItemChildClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
//
//                    Log.i("tag", "onItemChildClick: -----------------");
//                            vegetableClick.setVegetableClick(view,i);
//
//                }
//            });


        }
    }
}
